package com.cscec5b.inspection.repository;

import com.cscec5b.inspection.entity.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;


public interface ProjectRepository extends JpaRepository<Project, Long> {

    // 根据userCode查询项目
        @Query(value = """
        SELECT * FROM projects p
        WHERE p.project_members IS NOT NULL
          AND JSON_CONTAINS(p.project_members, JSON_QUOTE(:userCode), '$')
        ORDER BY p.project_id DESC
        """, nativeQuery = true)
        List<Project> findByMemberUserCode(@Param("userCode") String userCode);


    // 根据项目id查询
    @Query("select p from Project p where p.projectInnerNumber = :code")
    Optional<Project> findByInnerNumber(@Param("code") String projectInnerNumber);
}


